<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/header.css" />
	</head>

	<body>
		
		<header class="mui-bar mui-bar-nav title">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
		    <a id="link_sublimt_nickname" class="mui-icon mui-icon-right-nav mui-pull-right" style="color: white;font-size: 14px;line-height: 25px;">完成</a>
		    <h1 class="mui-title title-color">设置昵称</h1>
		</header>
		<div class="mui-content" id="div_my_face">
		    <div class="mui-input-row">
		        <input type="text" id="txt_nickname" class="mui-input-speech mui-input-clear" placeholder="修改昵称">
		    </div>
		    
		</div>
		
		
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			
			mui.plusReady(function() {
				var user = app.getUserGlobalInfo();
				var nickname = user.nickname;
				var txt_nickname = document.getElementById("txt_nickname");
				txt_nickname.value = nickname;
				
				
				var link_sublimt_nickname = document.getElementById("link_sublimt_nickname");
				link_sublimt_nickname.addEventListener("tap", function() {
					var new_nickname = txt_nickname.value;
					if(new_nickname.length < 1) {
						app.showTip("昵称太短","error");
						return false;
					}
					if(new_nickname.length > 8) {
						app.showTip("昵称不能超过8位","error");
						return false;
					}
					
					plus.nativeUI.showWaiting("请稍后");
					
					
					mui.ajax(app.serverUrl + "/u/setNickname",{
							data:{
								userId:user.id,
								nickname:new_nickname
							},
							dataType:'json',//服务器返回json格式数据
							type:'post',//HTTP请求类型
							timeout:10000,//超时时间设置为10秒；
							headers:{'Content-Type':'application/json'},	              
							success:function(data){
								//服务器返回响应，根据响应结果，分析是否登录成功；
								plus.nativeUI.closeWaiting();
								if(data.status == 200) {
									//保存全局用户对象到本地缓存
									var userInfoJson = data.data;
									app.setUserGlobalInfo(userInfoJson);
									
									var ty_webview = plus.webview.getWebviewById("myHome.html");
									mui.fire(ty_webview, "refresh");
									
									mui.back();
								} else {
									app.showTip(data.msg,"error");
									return false;
								}
							}
						});
					
				});
			});
		</script>
	</body>

</html>